home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-05-14 | 9.4 KB | 308 lines |
- import ComponentApp;
-
- public class TimeBasedComp extends ComponentApp
- {
- int maxWidth;
- int maxHeight;
- int numImages;
- static final int MaxImages=24;
- DDrawJava theJavaApplet;
- int[] imageNames;
- int[] imageURLs;
- int[] imageStarts;
- DAssetManager assetMan;
-
- public void onCopy()
- {
- int[] imageNamesOld=imageNames;
- int[] imageURLsOld=imageURLs;
- imageNames=new int[MaxImages];
- imageURLs=new int[MaxImages];
- for(int cnt=0;cnt<numImages;cnt++)
- {
- imageNames[cnt]=imageNamesOld[cnt];
- imageURLs[cnt]=imageURLsOld[cnt];
- if(imageNames[cnt]!=0)
- assetMan.CopyAsset(imageNames[cnt]);
- if(imageURLs[cnt]!=0)
- assetMan.CopyAsset(imageURLs[cnt]);
- }
- }
-
-
- public String onInstall(DAssetManager cam, String codebase)
- {
- assetMan=cam;
- return "Time Based Picture";
- }
-
- public void onInspect(CStringArray Names,CStringArray Types)
- {
- Names.Set("Number of Images");
- Types.Set(typeJavaCollection);
- for(int cnt=0; cnt<numImages; cnt++)
- {
- Names.Set("Image "+Integer.toString(cnt+1));
- Types.Set(typeImage);
- Names.Set("URL for Image "+Integer.toString(cnt+1));
- Types.Set(typeLink);
- Names.Set("Start Time for Image "+Integer.toString(cnt+1));
- Types.Set("Set(12am|1am|2am|3am|4am|5am|6am|7am|8am|9am|10am|11am|12pm|1pm|2pm|3pm|4pm|5pm|6pm|7pm|8pm|9pm|10pm|11pm)");
- }
-
- }
-
- public String PropertyListener(String Event,String Value,int Get, int propIndex, IDInspector insp)
- {
- if (Get == 1)
- {
- if (Event.compareTo("Number of Images") == 0)
- {
- return Integer.toString(numImages);
- }
- else
- {
- for(int cnt=0; cnt<numImages; cnt++)
- {
- if (Event.compareTo("Image "+Integer.toString(cnt+1))==0)
- return Integer.toString(imageNames[cnt]);
- if (Event.compareTo("URL for Image "+Integer.toString(cnt+1))==0)
- return Integer.toString(imageURLs[cnt]);
- if (Event.compareTo("Start Time for Image "+Integer.toString(cnt+1))==0)
- return Integer.toString(imageStarts[cnt]);
- }
- }
- }
- else
- {
- if (Event.compareTo("Number of Images") == 0)
- {
- int newNumImages=Integer.parseInt(Value,10);
- if(newNumImages>MaxImages)
- newNumImages=MaxImages;
- if(newNumImages<numImages)
- {
- DImage imageSizer=new DImage();
- maxHeight=maxWidth=0;
- for(int iter=0;iter<newNumImages;iter++)
- {
- String theImageFile=assetMan.GetAssetLocation(imageNames[iter], IAssetContext.Preview, IFileNameStyle.DosName);
- imageSizer.setImageFile(theImageFile);
- IDSize currentImageSize=imageSizer.getSize();
- if(currentImageSize.getHeight()>maxHeight)
- {
- maxHeight=currentImageSize.getHeight();
- }
- if(currentImageSize.getWidth()>maxWidth)
- {
- maxWidth=currentImageSize.getWidth();
- }
- }
- theJavaApplet.SetSize(maxWidth, maxHeight);
- }
- while(newNumImages<numImages)
- {
- assetMan.RemoveAsset(imageNames[--numImages]);
- }
- numImages=newNumImages;
- theJavaApplet.AddParam(Event,typeString,Value);
- }
- else
- {
- for(int cnt=0; cnt<numImages; cnt++)
- {
- if (Event.compareTo("Image "+Integer.toString(cnt+1))==0)
- {
- if(imageNames[cnt]!=0)
- {
- assetMan.RemoveAsset(imageNames[cnt]);
- }
- imageNames[cnt]=Integer.parseInt(Value,10);
- String theImageFile=assetMan.GetAssetLocation(imageNames[cnt], IAssetContext.Preview, IFileNameStyle.DosName);
- theJavaApplet.setImageFile(theImageFile);
- DImage imageSizer=new DImage();
- maxHeight=maxWidth=0;
- for(int iter=0;iter<numImages;iter++)
- {
- theImageFile=assetMan.GetAssetLocation(imageNames[iter], IAssetContext.Preview, IFileNameStyle.DosName);
- imageSizer.setImageFile(theImageFile);
- IDSize currentImageSize=imageSizer.getSize();
- if(currentImageSize.getHeight()>maxHeight)
- {
- maxHeight=currentImageSize.getHeight();
- }
- if(currentImageSize.getWidth()>maxWidth)
- {
- maxWidth=currentImageSize.getWidth();
- }
- }
- theJavaApplet.SetSize(maxWidth, maxHeight);
- }
- if (Event.compareTo("URL for Image "+Integer.toString(cnt+1))==0)
- imageURLs[cnt]=Integer.parseInt(Value,10);
- if (Event.compareTo("Start Time for Image "+Integer.toString(cnt+1))==0)
- {
- if(cnt!=0)
- {
- imageStarts[cnt]=Integer.parseInt(Value,10);
- if(imageStarts[cnt]>23)
- imageStarts[cnt]=23;
- else if(imageStarts[cnt]<0)
- imageStarts[cnt]=0;
- }
- }
- }
- }
-
-
- }
- return "";
- }
-
-
- public void onDrop(IDLayout layout, IDRect r, int fDrop)
- {
- if (fDrop != ActivateState.Drop) // the first time the component is dropped
- return;
-
- maxWidth=0;
- maxHeight=0;
-
- int xPos;
- int yPos;
-
- numImages=3;
- imageURLs=new int[24];
- imageNames=new int[24];
- imageStarts=new int[24];
- for(int i=0;i<24;i++)
- {
- imageNames[i]=0;
- imageURLs[i]=0;
- imageStarts[i]=i;
- }
- theJavaApplet = new DDrawJava();
- theJavaApplet.setImageFile(theJavaApplet.getCodeBase() + "banner.gif");
- theJavaApplet.setAppletFileName(theJavaApplet.getCodeBase() + "TimeBased.class");
- theJavaApplet.setStretch(PictureStretchMode.DRAW_NATURAL);
- theJavaApplet.setAltTag("Time Based Loader");
- xPos=r.getLeft();
- yPos=r.getTop();
- layout.AddObject(theJavaApplet);
- theJavaApplet.AddParam("Number of Images",typeString,"3");
- imageNames[0] = assetMan.AddAsset(theJavaApplet.getCodeBase()+"banner.gif",IAssetType.Image,"");
- imageNames[1] = assetMan.AddAsset(theJavaApplet.getCodeBase()+"banner2.gif",IAssetType.Image,"");
- imageNames[2] = assetMan.AddAsset(theJavaApplet.getCodeBase()+"banner3.gif",IAssetType.Image,"");
- DImage imageSizer=new DImage();
- imageSizer.setImageFile(theJavaApplet.getCodeBase() + "banner.gif");
- IDSize currentImageSize=imageSizer.getSize();
- if(currentImageSize.getHeight()>maxHeight)
- {
- maxHeight=currentImageSize.getHeight();
- if(currentImageSize.getWidth()>maxWidth)
- maxWidth=currentImageSize.getWidth();
- theJavaApplet.SetPositionRect(xPos, yPos, xPos+maxWidth, yPos+maxHeight);
- }
- else if(currentImageSize.getWidth()>maxWidth)
- {
- maxWidth=currentImageSize.getWidth();
- theJavaApplet.SetPositionRect(xPos, yPos, xPos+maxWidth, yPos+maxHeight);
- }
- }
-
- public void onUnInstall(DAssetManager cam)
- {
-
- }
-
- protected void finalize()
- {
- for(int cnt=0;cnt<numImages;cnt++)
- {
- if(imageNames[cnt]!=0)
- assetMan.RemoveAsset(imageNames[cnt]);
- }
- }
-
- public void onPublish(DAssetManager asm, int context)
- {
-
- if(context==IAssetContext.Preview)
- {
- for(int cnt=0;cnt<numImages;cnt++)
- {
- String theLoc=assetMan.GetAssetLocation(imageNames[cnt],context, IFileNameStyle.HTMLName);
- theLoc.replace('|',':');
- theJavaApplet.AddParam("Image "+Integer.toString(cnt+1),typeString,"file:///"+theLoc);
- }
- }
- else
- {
- for(int cnt=0;cnt<numImages;cnt++)
- {
- theJavaApplet.AddParam("Image "+Integer.toString(cnt+1),typeString,assetMan.GetAssetRelativeLocation(imageNames[cnt],context, 0));
- }
- }
- for(int cnt=0;cnt<numImages;cnt++)
- {
- String theURL;
- if(imageURLs[cnt]!=0)
- {
- theURL=assetMan.GetAssetLocation(imageURLs[cnt], context, IFileNameStyle.DosName);
- }
- else
- {
- theURL="";
- }
- theJavaApplet.AddParam("URL for Image "+Integer.toString(cnt+1),typeString,theURL);
- theJavaApplet.AddParam("Start Time for Image "+Integer.toString(cnt+1),typeString,Integer.toString(imageStarts[cnt]));
- }
- theJavaApplet.AddParam("Image Width",typeString,Integer.toString(maxWidth));
- theJavaApplet.AddParam("Image Height",typeString,Integer.toString(maxHeight));
-
- IDRect thePosition=theJavaApplet.getObjectRect();
- theJavaApplet.AddParam("X Position",typeString,Integer.toString(thePosition.getLeft()));
- theJavaApplet.AddParam("Y Position",typeString,Integer.toString(thePosition.getTop()+7));
-
- IDLayout layout = theJavaApplet.getLayout();
- IDSite site = layout.getSite();
- IDStyle style = site.getCurrentStyle();
-
-
- int backgroundStyle = layout.getBackgroundStyle();
-
- if (backgroundStyle != BackgroundStyle.None)
- {
- if (backgroundStyle == BackgroundStyle.SolidColor)
- theJavaApplet.AddParam("BackgroundColor",typeString,Integer.toString(layout.getBackgroundColor()));
- else if (backgroundStyle == BackgroundStyle.Image)
- {
- int backID = assetMan.AddAsset(layout.getBackgroundImage(),IAssetType.Image,"");
- String theParam=assetMan.GetAssetRelativeLocation(backID,context,1);
- if(context == IAssetContext.Preview)
- theParam="file:///"+theParam;
- theJavaApplet.AddParam("BackgroundImage",typeString,theParam);
- }
- }
- else
- {
- backgroundStyle = style.getBackgroundStyle();
-
- if (backgroundStyle == BackgroundStyle.SolidColor)
- theJavaApplet.AddParam("BackgroundColor",typeString,Integer.toString(style.getBackgroundColor()));
- else if (backgroundStyle == BackgroundStyle.Image)
- {
- int backID = assetMan.AddAsset(style.getBackgroundImage(),IAssetType.Image,"");
- String theParam=assetMan.GetAssetRelativeLocation(backID,context,1);
- if(context == IAssetContext.Preview)
- theParam="file:///"+theParam;
- theJavaApplet.AddParam("BackgroundImage",typeString,theParam);
- }
- }
-
- }
-
-
-
-
- }